package com.beerandjesus.webapp.sportofkings.handicapper.struts.action;

import com.beerandjesus.sportofkings.handicapper.dao.Database;
import com.beerandjesus.sportofkings.handicapper.model.JockeyRating;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;
import java.util.Collections;
import java.util.Comparator;

/**
 * View the contents of a database
 * Date: Jun 1, 2012
 * Time: 1:57:03 PM
 */
public class ViewDBContentsAction extends ActionSupport {
    private Database database;


    private List<JockeyRating> ratings;

    public String execute() throws Exception {
        List<JockeyRating> r = getDatabase().getAllJockeyRatings();
        Collections.sort(r, new Comparator<JockeyRating>() {
            public int compare(JockeyRating o, JockeyRating o1) {
                return o1.getRating().compareTo(o.getRating());
            }
        });
        setRatings(r);
        return SUCCESS;
    }

    public List<JockeyRating> getRatings() {
        return ratings;
    }

    public void setRatings(List<JockeyRating> ratings) {
        this.ratings = ratings;
    }

    public Database getDatabase() {
        return database;
    }

    public void setDatabase(Database database) {
        this.database = database;
    }
}
